package com.atguigu.adapter.objectdapter;

/**
 * 适配器类
 * @author gcq
 * @Create 2020-10-04
 */
public class VoltageAdapter  implements IVoltage5V {
    private Voltage220V voltage220V;

    // 通过构造器传入一个Voltage220V实例
    public VoltageAdapter(Voltage220V voltage220V) {
        this.voltage220V = voltage220V;
    }

    @Override
    public int output5V() {
        // 获取220v电压
        int dstV = 0;
        if (null != voltage220V) {
            int srcV = voltage220V.output220V();
            System.out.println("使用对象适配器进行适配");
            dstV = srcV / 44; // 转成5V
            System.out.println("适配完成，输出的电压=" + dstV);
        }
        return dstV;

    }
}
